<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>list</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="js/jquery-easyui-1.2.6/jquery-1.7.2.min.js"></script>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.2.6/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.2.6/themes/icon.css" />
	<script type="text/javascript" src="js/jquery-easyui-1.2.6/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="js/jquery-easyui-1.2.6/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript">
		$(function(){
    		$('#datagrid').datagrid({
				url: '<%=basePath%>weixinUserInfoServlet?action=list',
				title:'用户列表',
				striped: true,//显示条纹
				sortName: 'openId',//默认排序字段
				sortOrder: 'desc',//排序顺序asc,desc
				idField:'openId',//id字段，表明该列是一个唯一列。
	            rownumbers:true, //行号
	            selectOnCheck:true,
				singleSelect:true,
				pagination:true,//分页控件
				pageSize: 10,//每页记录数       
	            pageList: [5,10,15,20,25], //分页记录数数组
				loadMsg:'正在查询，请稍等...',
				fitColumns: true,//自适应列宽
				onDblClickRow:function(rowIndex, rowData){
					viewDetail(rowData.openId);
				},
				columns:[[
				    {field:'openId',title:'OPENID',width:10,align:'center',checkbox:true},
				    {field:'subscribe',title:'是否关注',width:25,align:'center'},
				    {field:'subscribeTime',title:'关注时间',width:40,align:'center'},
				    {field:'nickname',title:'昵称',width:30,align:'center'},
				    {field:'sex',title:'性别',width:15,align:'center'},
				    {field:'country',title:'国家',width:20,align:'center'},
				    {field:'province',title:'省份',width:20,align:'center'},
				    {field:'city',title:'城市',width:20,align:'center'},
				    {field:'language',title:'语言',width:20,align:'center'},
				    {field:'headImgUrl',title:'头像地址',width:100,align:'center'},
				    {field:'privileges',title:'特权',width:15,align:'center'}
				]]
				
			});
    		
    	});
    	
    	
    	//删除
    	function deleteUser(){
    		var row = $('#datagrid').datagrid('getSelected');
            if (row) {
                $.messager.confirm('提示', '确定删除选中的记录?', function (r) {
                    if (r) {
                        $.post('weixinUserInfoServlet?action=delete', { openId: row.openId }, function (result) {
                            if ("1" == result) {
                            	$.messager.alert("提示信息", "删除成功");
                                $("#datagrid").datagrid('reload');    
                            } else {
                            	$.messager.alert("提示信息", "删除失败");
                            }
                        }, 'json');
                    }
                });
            }
    	}
    	
    	//查询
    	function query() {
    	    $('#datagrid').datagrid('reload',{
    	    'nickname': $("#nickname").val()
    	        });
    	}

    	//重置
    	function reset() {
    		$("#queryform").form("clear");
    	}
    	
    	
	</script>
  </head>
  
  <body>
  		<!-- 操作区域 -->
 	<div id="tab">
		<table>
			<a href="javascript:#" class="easyui-linkbutton" iconCls="icon-add" plain="true" style="color: gray">添加</a>
			<a href="javascript:#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" style="color: gray">修改</a>
			<a href="javascript:deleteUser()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
		</table>
	</div>
  	<!-- 查询条件区域 -->
	  <div id="search_area" >
	    <form action="" id="queryform">
	      <table border="0">
	        <tr>
	          <td>&nbsp;昵称：</td>
	          <td><input  name="nickname" id="nickname"  /></td>
	          <td>
	              <a  href="javascript:void(0)" class="easyui-linkbutton my-search-button" iconCls="icon-search" plain="true" onclick="query()">查询</a> 
	              <a  href="javascript:void(0)" class="easyui-linkbutton my-search-button" iconCls="icon-undo" plain="true" onclick="reset()">重置</a>
	          </td>
	        </tr>
	      </table>
	     </form>
	  </div>
  	
  	<!-- 数据表格区域 -->
 	<div id="datagrid"></div>
    
  </body>
</html>
